package tamgiac;

import java.util.Arrays;
import java.util.Scanner;


import diem.Diem;

public class TamGiac {

	/**
	 * @param args
	 */
	private Diem A;
	private Diem B;
	private Diem C;
	
	public Diem getA() {
		return A;
	}

	public void setA(Diem a) {
		A = a;
	}

	public Diem getB() {
		return B;
	}

	public void setB(Diem b) {
		B = b;
	}

	public Diem getC() {
		return C;
	}

	public void setC(Diem c) {
		C = c;
	}

	/**
	 * @param a
	 * @param b
	 * @param c
	 * 
	 */
	public TamGiac(Diem a, Diem b, Diem c) {
		super();
		A = a;
		B = b;
		C = c;
	}

	/**
	 * 
	 */
	public TamGiac(TamGiac t) {
		super();
		// TODO Auto-generated constructor stub
		this.A = t.A;
		this.B = t.B;
		this.C = t.C;
	}
	

	/**
	 * 
	 */
	public TamGiac() {
		super();
		// TODO Auto-generated constructor stub
		
		this.A = new Diem();
		this.B = new Diem();
		this.C = new Diem();
	}

	//nhap tam ggiac 
	public void Nhap(){
		System.out.println("Nhap tam giac : ");
				
		System.out.println("Nhap diem A : ");
		
		this.A.Nhap();
		System.out.println("Nhap diem B : ");
		
		this.B.Nhap();
		System.out.println("Nhap diem C : ");
		
		this.C.Nhap();
		
	}
	//Override
	public void Nhap (String tieude){
		System.out.print(tieude);
		System.out.println("Nhap diem A : ");
		
		this.A.Nhap();
		System.out.println("Nhap diem B : ");
		
		this.B.Nhap();
		System.out.println("Nhap diem C : ");
		
		this.C.Nhap();
	}
	//xuat tam giac 
	public void Xuat(){
		System.out.println("tam giac ABC : ");
		this.A.Xuat();
		this.B.Xuat();
		this.C.Xuat();
	}
	
	// tinh chu vi
	public double ChuVi() {
		return A.KhoangCach(B) + B.KhoangCach(C) + C.KhoangCach(A);
	}

	//tinh dien tich 
	public double DienTich(){
		double a = A.KhoangCach(B);
		double b = A.KhoangCach(C);
		double c = B.KhoangCach( A);
		double p = this.ChuVi()/2;
		
		return Math.sqrt(p* (p-a)*(p-b)*(p-c));
	}
	//tim trong tam
	public Diem TrongTam() { // chua chinh xac vi diem la kieu int
		Diem G = new Diem();
		G.setX((A.getX() + B.getX() + C.getX())/3);
		G.setY((A.getY() + B.getY() + C.getY())/3);
		
		return G; 
		
	}
	//xac dinh tam giac Deu
	public String XD_TamGiacDeu() {
		double a = A.KhoangCach(B);
		double b = A.KhoangCach(C);
		double c = B.KhoangCach( A);
		
		if(a == b && b==c){
			return "Tam giac deu";
		}
		return "Khong phai tam giac deu";
		
	}
	
	//xac dinh tam giac can
	
	public String XD_TamGiacCan() {
		double a = A.KhoangCach(B);
		double b = A.KhoangCach(C);
		double c = B.KhoangCach( A);
		
						
		if(((a == b )&& (a != c)) || ((b == c)&& (b != a)) || ((a == c )&& (a != b))){
			return "Tam giac Can";
		}
		return "Khong phai tam giac can";
		
	}
	
	//xac dinh tam giac vuong
	
	public String XD_TamGiacVuong() {
		double a = A.KhoangCach(B);
		double b = A.KhoangCach(C);
		double c = B.KhoangCach( A);
		
		double [] arr = {a,b,c};
		Arrays.sort(arr);
		
		if(arr[2]* arr[2] == arr[0]*arr[0] + arr[1]* arr[1]){
			return "Tam giac vuong";
		}
		return "Khong phai tam giac vuong";
		
	}
	
	//parse da giac 
	public static TamGiac paseTamGiac() {
		
		System.out.print("nhap chuoi dang Ax,Ay;Bx,By;Cx,Cy ");
		Scanner scan = new Scanner(System.in);
		
		String str = scan.nextLine();
		
		String [] arrStr = str.split(";");
		
		
		TamGiac t = new TamGiac();
		t.A = Diem.parseDiem(arrStr[0]);		
		t.B = Diem.parseDiem(arrStr[1]);
		t.C = Diem.parseDiem(arrStr[2]);
		
		return t;
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TamGiac t = new TamGiac ();
		t.Nhap();
		t.Xuat();
		
		System.out.println("Chu vi tam giac : " + t.ChuVi() );
		System.out.println("Dien Tich tam giac : " + t.DienTich());
		System.out.print("Trong tam tam giac : " );
		t.TrongTam().Xuat();
		
		t.XD_TamGiacCan();
		t.XD_TamGiacDeu();
		t.XD_TamGiacVuong();
		TamGiac.paseTamGiac().Xuat();
		
		t.Nhap("nhap tam giac moi : ");
		t.Xuat();
	}

}
